<template>
  <!-- git配置模态框 -->
  <el-dialog
    :title="$t('projectDialog.title.git')"
    :visible.sync="DialogShow"
    width="50%"
    :before-close="closeDialogCan"
    @opened="opened"
  >
    <span class="main"
      ><el-form
        ref="createdFormRef"
        :label-position="labelPosition"
        label-width="150px"
        :model="form"
        :rules="rules"
      >
        <el-form-item :label="$t('projectDialog.form.git')" prop="address">
          <el-input v-model="form.address"></el-input>
        </el-form-item>
        <el-form-item :label="$t('projectDialog.form.clone')" prop="to_address">
          <el-input v-model="form.to_address"></el-input>
        </el-form-item>
      </el-form>
    </span>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialogCan">{{
        $t("projectDialog.btn.cancel")
      }}</el-button>
      <el-button type="warning" plain @click="resetForm">{{
        $t("projectDialog.btn.reset")
      }}</el-button>
      <el-button type="primary" @click="addPersonnel" style="width: 200px">{{
        $t("projectDialog.btn.save")
      }}</el-button>
    </span>
    <!-- <fileSrc></fileSrc> -->
  </el-dialog>
</template>

<script>
import fileSrc from "./fileBox/fileSrc.vue";
export default {
  props: ["DialogShow", "form"],
  components: { fileSrc },
  data() {
    return {
      labelPosition: "right",
      // 验证规则
      rules: {
        address: [
          {
            required: true,
            trigger: "blur",
            message: this.$t("projectDialog.form.git_message"),
          },
        ],
        to_address: [
          {
            required: true,
            trigger: "blur",
            message: this.$t("projectDialog.form.clone_message"),
          },
        ],
      },
    };
  },
  methods: {
    opened() {
      console.log(this.form);
      console.log(this.form.to_address);
      if (this.form.to_address != null) return;
      this.form.to_address = "/root/code/projects";
    },
    // 创建爬虫
    addPersonnel() {
      console.log(this.form);
      this.$refs.createdFormRef.validate((valid) => {
        if (!valid) return;
        delete this.form.reptileChildren;
        delete this.form.taskChildren;
        this.$http
          .post("/git/config", {
            id: this.form.id,
            address: this.form.address,
            to_address: this.form.to_address,
          })
          .then((res) => {
            console.log(res);
            if (res.status == 200) {
              if (res.data.code == 0) {
                // this.$refs.createdFormRef.resetFields();
                this.$message.success(
                  this.$t("projectDialog.form.save_message")
                );
                this.closeDialog();
              } else {
                this.$message.error(
                  this.$t("projectDialog.form.save_error_message")
                );
              }
            } else {
              this.$message.error(
                this.$t("projectDialog.form.save_error_message")
              );
            }
          });
      });
    },
    resetForm() {
      this.$refs.createdFormRef.resetFields();
    },
    // 关闭弹出框
    closeDialog() {
      this.$emit("closeDialog");
    },
    closeDialogCan() {
      this.$emit("closeDialog", "1");
    },
  },
};
</script>

<style lang='less' scoped>
.el-form-item {
  width: 80%;
}
</style>